package com.church.action;

import java.util.Date;

import com.church.db.User;
import com.church.services.UserServices;
import com.opensymphony.xwork2.ActionSupport;

public class Register extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserServices userServices;
	private String name;
	private String password;
	private String passwordAgain;
	private boolean sex;
	private Date birthday;
	private String graduated;
	private String address;
	private String mobile;
	private String telephone;
	private String email;
	private String workingOrgans;
	private String workPosition;
	private String artisticSkills;

 
	public UserServices getUserServices() {
		return userServices;
	}

	public void setUserServices(UserServices userServices) {
		this.userServices = userServices;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordAgain() {
		return passwordAgain;
	}

	public void setPasswordAgain(String passwordAgain) {
		this.passwordAgain = passwordAgain;
	}

	public boolean isSex() {
		return sex;
	}

	public void setSex(boolean sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getGraduated() {
		return graduated;
	}

	public void setGraduated(String graduated) {
		this.graduated = graduated;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getWorkingOrgans() {
		return workingOrgans;
	}

	public void setWorkingOrgans(String workingOrgans) {
		this.workingOrgans = workingOrgans;
	}

	public String getWorkPosition() {
		return workPosition;
	}

	public void setWorkPosition(String workPosition) {
		this.workPosition = workPosition;
	}

	public String getArtisticSkills() {
		return artisticSkills;
	}

	public void setArtisticSkills(String artisticSkills) {
		this.artisticSkills = artisticSkills;
	}

	public void validate() {
		if (!password.equals(passwordAgain)) {
			addFieldError("passwordAgain", "second password error!");
		}
		User user = userServices.findUserByName(name);
		if(user!=null)
		{
			addFieldError("name", "user name exist!");
		}
	}

	public String execute() {
		User user=new User();
		user.setAddress(address);
		user.setArtisticSkills(artisticSkills);
		user.setBirthday(birthday);
		Date datetime = new Date(System.currentTimeMillis());
		user.setCreateDate(datetime);
		user.setEmail(email);
		user.setGraduated(graduated);
		user.setMobile(mobile);
		user.setName(name);
		user.setPassword(password);
		user.setSex(sex);
		user.setState("0");
		user.setType("user");
		user.setGroup("user");
		return userServices.register(user);
	}

}
